package com.fjxd.feign.result;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author csw
 * 后端向前端的交互类型
 */
@Data
@NoArgsConstructor
public class ViewResult {
    private Integer code;
    private String message;
    private Object data;

    public ViewResult(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ViewResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public static ViewResult success(){
        return new ViewResult(Status.SUCCESS.getCode(), Status.SUCCESS.getMessage());
    }
    public static ViewResult success(Object data){
        return new ViewResult(Status.SUCCESS.getCode(), Status.SUCCESS.getMessage(), data);
    }

    public enum Status {
        SUCCESS(200, "请求成功"),
        REDIRECT(302, "跳转"),
        NOUSER(222, "请确认您的账户或密码正确..."),
        IDCARD(443, "身份证格式错误"),
        INUSER(111, "该用户已存在..."),
        BADREQUEST(400, "请求参数有误"),
        FORBIDDEN(403, "拒绝服务"),
        NOTFOUND(404, "资源不存在"),
        SERVERERROR(500, "服务器不可预期错误");
        private int code;
        private String message;

        Status(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }
}
